﻿using ReverseEGNs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace ReverseEGN.Test
{
    [TestClass()]
    public class ReverseEGNsTest
    {
        [TestMethod()]
        public void ExtractEGNTest()
        {
            string input = "088 / 12-34-56. I have 2 sons. Peter is the oldest. His EGN is: 6203120707.";
            ReverseEGNs_Accessor.ExtractEGN(input);
            string expected = "6203120707";
            Assert.AreEqual(expected, ReverseEGNs_Accessor.Egns[0]);
        }

        [TestMethod()]
        [DeploymentItem("ReverseEGNs.exe")]
        public void MainTest()
        {
            ReverseEGNs_Accessor.Main();
        }

        [TestMethod()]
        [DeploymentItem("ReverseEGNs.exe")]
        public void ReadFileTest()
        {
            string inputFile = "../../../EGNExtractor/persons.txt";
            ReverseEGNs_Accessor.ReadFile(inputFile);
        }

        [TestMethod()]
        [ExpectedException(typeof(FileNotFoundException))]
        public void ReadWrongFileTest()
        {
            string inputFile = "alabala";
            ReverseEGNs_Accessor.ReadFile(inputFile);
        }

        [TestMethod()]
        [DeploymentItem("ReverseEGNs.exe")]
        public void ReplaceEGNTest()
        {
            string outputFile = "../../test.txt";
            string expected = "Of dragons and the blood on their claws.";
            ReverseEGNs_Accessor.ReplaceEGN(outputFile, expected);
            StreamReader reader = new StreamReader(outputFile);
            string actual;
            using (reader)
            {
                actual = reader.ReadToEnd();
            }
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        [DeploymentItem("ReverseEGNs.exe")]
        public void ReverseEGNTest()
        {
            string egn = "abvgdej";
            string expected = "jedgvba";
            string actual;
            actual = ReverseEGNs_Accessor.ReverseEGN(egn);
            Assert.AreEqual(expected, actual);
        }
    }
}
